import { _decorator, Component, Node } from 'cc';
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
import { ModuleUtil } from 'db://oops-framework/module/common/ModuleUtil';
import { MatchViewComp } from './view/MatchViewComp';
import { UIID } from '../common/config/GameUIConfig';
import { smc } from '../common/SingletonModuleComp';
import { RoomInfo } from '../../tsrpc/shared/type/RoomInfo';
const { ccclass, property } = _decorator;

@ecs.register(`Match`)
export class Match extends ecs.Entity {
    protected init() {
        ModuleUtil.addViewUiAsync(this, MatchViewComp, UIID.Match);
    }

    async getRoomList() {
        var ret = await smc.net.hcMatch.callApi('RoomList', {});
        if (ret.isSucc) {
            return ret.res.rooms;
        } else {
            return []
        }
    }

    async createRoom(roomName:string) {
        var ret = await smc.net.hcMatch.callApi("CreateRoom", {roomName});
        if (ret.isSucc) {
            return ret.res.roomInfo;
        } else {
            return null
        }
    }

    async joinRoom(roomId:number) {
        var ret = await smc.net.hcMatch.callApi("JoinRoom", {roomId});
        if (ret.isSucc) {
            return ret.res.isEnter;
        } else {
            return false
        }
    }
}

export class EcsMatchSystem extends ecs.System {
    constructor() {
        super();

        //this.add(new LoginNetSystem());
    }
}


